import {
    getDicType,
    getStationByCompanyId,
    getUserAutList,
    get_simple_organization,
    get_simple_user_list,
    get_simple_user_listBycompanyId
} from "@/api/common.js";
import { getDisClostDetail } from "@/api/internetSales/projectClarifi.js";
import { graphic_list } from "@/api/smart/schedul/b.js";
import {
    cancelPlanByIds,
    getLists,
    planRemark
} from "@/api/smart/schedul/c.js";
import {
    engineeringManagementQueryListFinish,
    engineeringManagementQueryPage,
    getContractVoList,
    get_assess,
    job_arrangement,
    operation_detail,
    planDetail,
    plan_detail,
    plan_detail_and_child,
    plan_table_detail,
    queryConfiguration,
    queryPage,
    query_product_page,
    save_or_update,
    updateConfiguration,
    updateOrderStatus,
    queryCooperationEngineering
} from "@/api/smart/schedul/d.js";
import { assign_list } from "@/api/smart/schedul/f.js";
import mixin from "@/mixins/ICPSmixin.js";
import { getUserInfo } from "@/utils/auth.js";
import moment from "moment";
import outsourcing from "./outsourcing"; //引入外协拉料
export default {
  components: {
    //启动组件
    Outsourcing: outsourcing,
  },
  mixins: [mixin],
  data() {
    return {
      pickerOptions: {
        disabledDate: this.limitTime,
      },
      ids: [],
      stationIdlist: [], //当前账号公司得所有站点
      UserInfo: "",
      approvalStatus0: "",
      customerCheckStatus0: "",
      tableParamType: false,
      companylist: [], //公司
      sitelist: [], //站点
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      /*表格数据*/
      table: [],
      tableData1: [],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      contractTypelist: [
        {
          value: "订单列表",
          id: 0,
        },
        {
          value: "生产调整",
          id: 1,
        },
        {
          value: "外协拉料",
          id: 2,
        },
      ],
      currenindex: 0,
      tableA: [
        {
          label: "订单编号",
          width: "220",
          prop: "orderNo",
          status: true,
        },
        {
          label: "工程名称",
          width: "160",
          prop: "engineeringName",
          status: true,
        },
        {
          label: "浇筑部位",
          width: "220",
          prop: "structuralParts",
          status: true,
        },
        {
          label: "产品名称",
          prop: "productName",
          width: "140",
          status: true,
        },
        {
          label: "浇筑用量（方）",
          width: "140",
          prop: "pouringNum",
          status: true,
        },
        {
          label: "计划浇筑时间",
          prop: "pouringTime",
          width: "160",
          status: true,
        },
        {
          label: "浇筑方式",
          width: "140",
          prop: "pouringMethod",
          status: true,
        },
        {
          label: "客户名称",
          width: "180",
          prop: "customerName",
          status: true,
        },
        {
          label: "联系人",
          width: "120",
          prop: "person",
          status: true,
        },
        {
          label: "销售员",
          width: "120",
          prop: "salesPerson",
          status: true,
        },
        {
          label: "预算员",
          width: "120",
          prop: "budgetPerson",
          status: true,
        },
        {
          label: "联系电话",
          width: "140",
          prop: "phoneNum",
          status: true,
        },
        {
          label: "结算方式",
          width: "80",
          prop: "paymentMethod",
          status: true,
        },
        {
          label: "订单类型",
          width: "120",
          prop: "orderType",
          status: true,
        },
        {
          label: "下单时间",
          width: "160",
          prop: "createOrderTime",
          status: true,
        },
        {
          label: "审核状态",
          width: "80",
          prop: "",
          status: true,
        },
      ],
      tableB: [
        {
          label: "订单编号",
          width: "220",
          prop: "orderNo",
          status: true,
        },
        {
          label: "工程名称",
          width: "160",
          prop: "engineeringName",
          status: true,
        },
        {
          label: "浇筑部位",
          width: "220",
          prop: "structuralParts",
          status: true,
        },
        {
          label: "产品名称",
          width: "160",
          prop: "productName",
          status: true,
        },
        {
          label: "计划生产量（方）",
          width: "140",
          prop: "pouringNum",
          status: true,
        },
        {
          label: "计划浇筑时间",
          width: "160",
          prop: "pouringTime",
          status: true,
        },
        {
          label: "下单时间",
          width: "160",
          prop: "createOrderTime",
          status: true,
        },
        {
          label: "浇筑方式",
          width: "140",
          prop: "pouringMethod",
          status: true,
        },
        {
          label: "生产站点",
          width: "120",
          prop: "stationName",
          status: true,
        },
        {
          label: "结算方式",
          width: "80",
          prop: "paymentMethod",
          status: true,
        },
        {
          label: "订单类型",
          width: "120",
          prop: "orderType",
          status: true,
        },
        {
          label: "订单审核人",
          width: "140",
          prop: "submitOrderUserName",
          status: true,
        },
        {
          label: "状态",
          width: "120",
          prop: "",
          status: true,
        },
        {
          label: "操作",
          width: "80",
          prop: "",
          status: true,
        },
      ],
      lookType: false,
      formData: {
        contractId: "",
        engineeringId: "",
        strengthGradeId: "", //强度等级
        performanceGradeId: "", //性能等级
        meterialRequirementsId: "", //材料要求
        specialRequirementsId: "", //特殊要求
        otherRequirementsId: "", //其他要求list
        admixtureRequirements: "", //外加剂要求
        pouringMethod: "", //浇筑方式
        pouringTime: "", //浇筑时间
      },
      lookType2: false,
      /*添加表单数据*/
      rules: {
        structuralParts: [
          {
            required: true,
            message: "请输入浇筑部位",
            trigger: "change",
          },
        ],
        strengthGradeId: [
          {
            required: true,
            message: "请选择强度等级",
            trigger: "change",
          },
        ],
        performanceGradeId: [
          {
            required: true,
            message: "请选择性能等级",
            trigger: "change",
          },
        ],
        meterialRequirementsId: [
          {
            required: true,
            message: "请选择材料要求",
            trigger: "change",
          },
        ],
        specialRequirementsId: [
          {
            required: true,
            message: "请选择特殊要求",
            trigger: "change",
          },
        ],
        otherRequirementsId: [
          {
            required: true,
            message: "请选择其他要求",
            trigger: "change",
          },
        ],
        admixtureRequirements: [
          {
            required: true,
            message: "请选择外加剂要求",
            trigger: "change",
          },
        ],
        pouringMethod: [
          {
            required: true,
            message: "请选择浇筑方式",
            trigger: "change",
          },
        ],
        pouringTime: [
          {
            required: true,
            message: "请选择浇筑时间",
            trigger: "change",
          },
        ],
        pouringNum: [
          {
            required: true,
            message: "请输入浇筑用量",
            trigger: "change",
          },
        ],
        pouringHigh: [
          {
            required: true,
            message: "请输入泵送高度",
            trigger: "change",
          },
        ],
        person: [
          {
            required: true,
            message: "请输入联系人",
            trigger: "change",
          },
        ],
        phoneNum: [
          {
            required: true,
            message: "请输入联系电话",
            trigger: "change",
          },
          { min: 11, max: 11, message: "手机号格式错误", trigger: "change" },
        ],
      },
      rules2: {
        person: [
          {
            required: true,
            message: "请输入联系人",
            trigger: "blur",
          },
        ],
        phoneNum: [
          {
            required: true,
            message: "请输入联系电话",
            trigger: "blur",
          },
        ],
        pouringNum: [
          {
            required: true,
            message: "请输入浇筑用量",
            trigger: "blur",
          },
        ],
        pouringMethod: [
          {
            required: true,
            message: "请输入浇筑方式  ",
            trigger: "change",
          },
        ],
        pouringTime: [
          {
            required: true,
            message: "请选择浇筑时间",
            trigger: "change",
          },
        ],
        pouringHigh: [
          {
            required: true,
            message: "请输入泵送高度",
            trigger: "blur",
          },
        ],
        noteName: [
          {
            required: true,
            message: "请输入票单名称",
            trigger: "blur",
          },
        ],
      },
      rules2_2: {
        pointId: [
          {
            required: true,
            message: "请输入供应站点名称",
            trigger: "change",
          },
        ],
        settleId: [
          {
            required: true,
            message: "请输入结算方式",
            trigger: "change",
          },
        ],
        lossNumId: [
          {
            required: true,
            message: "请输入损耗量",
            trigger: "change",
          },
        ],
      },
      formData4: {},
      formData3Table: [], //调整里面的表格
      formData3TableCopy: [], //原始表格数据
      formData3TableTimeListCopy: [], //原始时间list
      formData3TableTimeListCopy2: [], //用于调整时间
      formData3TableTableCopy: [], //原始表头list
      toViewList2_1: [], //调整表头生产站点的自主生产list
      toViewList2_2: [], //调整表头生产站点的外协生产list
      toViewListIndex: "", //表格选中项下标
      addDialog2_2: false,
      engineeringName: "",
      engineeringId: "", //工程id
      planId: "", //计划id
      ToViewType: false,
      toViewList: [],
      tableInfo: {},
      addDialog: false,
      addDialog2: false,
      chooseType: false,
      engineeringManagement: [],
      strengthGradeList: [], //强度list
      performanceGradeList: [], //性能等级list
      meterialRequirementsList: [], //材料要求list
      specialRequirementsList: [], //特殊要求list
      otherRequirementsList: [], //其他要求list
      admixtureRequirementsList: [], //外加剂要求list
      pouringMethodList: [], //浇筑方式list
      structuralPartsList: [], //浇筑部位
      goodPriceList: [],
      formData2: {},
      formData2_2: { remark: "", foreman: "" },
      assess: { isPro: "" }, //是否限制生产 1是 0否
      totalPoureCount: "", //累计浇筑量
      ListArr: [],
      toViewList2: [],
      foremanIdList: [], //前场工长
      foremanIdList2: [], //后场工长
      foremanIdList3: [], //本次作业泵工
      ToViewFun3Name: "",
      radio: {},
      engineeringNameList: [], //工程名称
      orderType: "", //客户还是调整订单
      customerCheckStatus: false, //客户确认状态
      formData5: {},
      multipleSelection: {},
      marginNumberList: [],
      remarkList: [],
      startTimDateEndTimDate: [],
      contractIdList: [],
      addDialogText: "添加订单",
      list: "",
      look0Type: false,
      bussinessVisible: false,
      buspointArr: [],
      servicePoint: "",
      buspointids: [],
      assignment: false,
      checkList1: [],
      checkList2: [],
      checkList3: [],
      checkList4: [],
      signVisible: false,
      signParams: {
        signOperateMinutre: "",
        enable: "",
      },
      oldPermissionsList: [],
      stationList: [],
      customerCheckStatusCode: "",
      subOrderList: []
    };
  },
  async created() {
    /**
     * @Description: 消息通知进入页面
     * @param {*}
     * @Author: wangwangwang
     */
    const type = this.$route.query.type;
    if (type * 1 == 2) {
      this.currenindex = 1;
    }
    this.UserInfo = await getUserInfo();
    getStationByCompanyId({ id: this.UserInfo.companyId }).then((res) => {
      this.stationIdlist = res.data.map((v) => {
        return {
          id: v.stationId,
          name: v.stationName,
        };
      });
    });
    this.init();
    this.stationList = await getUserAutList(true);
    getDicType({
      code: "marginNumber",
    }).then((res) => {
      this.marginNumberList = res.data.items;
    });
    getDicType({
      code: "market",
    }).then((res) => {
      this.buspointArr = res.data.items.map((res) => {
        return { id: res.id, name: res.itemName };
      });
    });
  },
  deactivated() {
    this.addDialog2 = false;
  },
  methods: {
    exportSubmit() {
      this.$Download(
        "/icps/system/sign/basics/plan/exportPlanList",
        this.tableParam
      );
    },
    limitTime(time) {
      return (
        time.getTime() <
          new Date(this.formData2.pouringTime).getTime() -
            24 * 60 * 60 * 1000 ||
        time.getTime() >
          new Date(this.formData2.pouringTime).getTime() +
            3 * 24 * 60 * 60 * 1000
      );
    },
    updateOrderStatusFun(row) {
      this.$confirm("此操作将完成订单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        /**
         * @Description: 盘点逻辑 1.生产调整的生产量不能之和不能大于订单的浇筑用量
         * @param {*}
         * @Author: wangwangwang
         */
        const sum = this.formData2.list.reduce((p, e) => p + e.pouringNum, 0);
        if (sum > this.formData2.pouringNum) {
          this.$message.warning(
            "生产调整的生产量不能之和不能大于订单的浇筑用量"
          );
          return;
        }
        updateOrderStatus({ id: row.planId, customerCheckStatus: 4 }).then(
          (res) => {
            if (res.code == 1001) {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
              this.gettableData();
            }
          }
        );
      });
    },
    async modifyFun(row) {
      this.addDialog = true;
      this.$data.formData = this.$options.data().formData;
      this.$nextTick(() => {
        plan_detail({ id: row.planId }).then(async (res) => {
          this.formData = { ...this.formData, ...res.data };
          await this.contractIdListFun();
          await this.getListsFun();
          this.engineeringManagementQueryListFinishFun();
          if (this.formData.performanceGradeId) {
            this.formData.performanceGradeId = JSON.parse(
              this.formData.performanceGradeId
            ).map((v) => {
              return v.id;
            });
          } else {
            this.formData.performanceGradeId = [];
          }
          if (this.formData.meterialRequirementsId) {
            this.formData.meterialRequirementsId = JSON.parse(
              this.formData.meterialRequirementsId
            ).map((v) => {
              return v.id;
            });
          } else {
            this.formData.meterialRequirementsId = [];
          }
          if (this.formData.specialRequirementsId) {
            this.formData.specialRequirementsId = JSON.parse(
              this.formData.specialRequirementsId
            ).map((v) => {
              return v.id;
            });
          } else {
            this.formData.specialRequirementsId = [];
          }
          if (this.formData.otherRequirementsId) {
            this.formData.otherRequirementsId = JSON.parse(
              this.formData.otherRequirementsId
            ).map((v) => {
              return v.id;
            });
          } else {
            this.formData.otherRequirementsId = [];
          }
          if (this.formData.admixtureRequirements) {
            this.formData.admixtureRequirements = JSON.parse(
              this.formData.admixtureRequirements
            ).map((v) => {
              return v.id;
            });
          } else {
            this.formData.admixtureRequirements = [];
          }
          if (this.formData.pouringMethod) {
            this.formData.pouringMethod = JSON.parse(
              this.formData.pouringMethod
            ).map((v) => {
              return v.id;
            });
          } else {
            this.formData.pouringMethod = [];
          }
          this.$refs.reffromData.clearValidate();
        });
      });
    },
    /**
     * @Description: 获取5大参数、浇筑方式泵机类型
     * @Param:
     * @Author: wangwangwang
     */
    getListsFun() {
      getLists().then((res) => {
        res.data.forEach((item) => {
          if (!item) return;
          if (item.typeName == "强度等级") {
            this.strengthGradeList = item.list;
          } else if (item.typeName == "规范性能等级") {
            this.performanceGradeList = item.list;
          } else if (item.typeName == "材料要求") {
            this.meterialRequirementsList = item.list;
          } else if (item.typeName == "特殊要求") {
            this.specialRequirementsList = item.list;
          } else if (item.typeName == "外加剂要求") {
            this.admixtureRequirementsList = item.list;
          } else if (item.typeName == "其他要求") {
            this.otherRequirementsList = item.list;
          }
        });
      });
      /**浇筑方式泵机类型 */
      getDicType({
        code: "castingType",
      }).then((res) => {
        res.data.items.map((v1) => (v1.type = 1));
        this.pouringMethodList = res.data.items;
        getDicType({
          code: "pouringMethod",
        }).then((res) => {
          res.data.items.map((v2) => (v2.type = 2));
          this.pouringMethodList = [
            ...this.pouringMethodList,
            ...res.data.items,
          ];
          this.pouringMethodList.forEach((res) => {
            res.name = res.itemName;
          });
        });
      });
    },
    /**订单类型查询工程 */
    engineeringManagementQueryListFinishFun(type) {
      if (type) {
        this.formData.engineeringId = "";
      }
      let businessTypeId = "";
      if (this.formData.orderType * 1 === 5) {
        businessTypeId = 2;
      } else if (this.formData.orderType * 1 === 4) {
        businessTypeId = 3;
      } else if (this.formData.orderType * 1 === 3) {
        businessTypeId = 4;
      } else if (this.formData.orderType * 1 === 1) {
        //市场：交底通过，且在供应中
        engineeringManagementQueryPage({
          isAssess: 5,
          page: 1,
          pageSize: 9999999,
        }).then((res) => {
          this.engineeringNameList = res.data.data;
          this.$forceUpdate();
        });
        return;
      }
      engineeringManagementQueryListFinish({ businessTypeId }).then((res) => {
        this.engineeringNameList = res.data;
        this.$forceUpdate();
      });
    },
    /**浇筑部位选择后 */
    structuralPartsCheckFun() {
      this.formData.strengthGradeId = "";
      this.formData.performanceGradeId = "";
      this.formData.meterialRequirementsId = "";
      this.formData.specialRequirementsId = "";
      this.formData.otherRequirementsId = "";
      this.formData.admixtureRequirements = "";
      console.log(JSON.parse(JSON.stringify(this.structuralPartsList)));
      let item = this.structuralPartsList.find(
        (v) => v.id == this.formData.structuralParts
      );
      if (item) {
        this.formData.strengthGradeId = JSON.parse(item.strengthGrade)[0].id;
        if (item.performanceGrade) {
          this.formData.performanceGradeId = JSON.parse(
            item.performanceGrade
          ).map((v) => v.id);
        }
        if (item.meterialRequirements) {
          this.formData.meterialRequirementsId = JSON.parse(
            item.meterialRequirements
          ).map((v) => v.id);
        }
        if (item.specialRequirements) {
          this.formData.specialRequirementsId = JSON.parse(
            item.specialRequirements
          ).map((v) => v.id);
        }
        if (item.otherRequirements) {
          this.formData.otherRequirementsId = JSON.parse(
            item.otherRequirements
          ).map((v) => v.id);
        }
        if (item.admixtureRequirements) {
          this.formData.admixtureRequirements = JSON.parse(
            item.admixtureRequirements
          ).map((v) => v.id);
        }
      }
    },
    /**工程选择后查询浇筑部位 */
    addDialogFun() {
      console.log(11);
      let day3 = new Date();
      day3.setTime(day3.getTime() + 24 * 60 * 60 * 1000);
      var s3 =
        day3.getFullYear() + "-" + (day3.getMonth() + 1) + "-" + day3.getDate();
      this.formData.pouringTime =
        new Date(s3).Format("yyyy-MM-dd") + " 08:00:00";
      this.formData.engineeringName = this.engineeringName;
      graphic_list({ engineeringId: this.formData.engineeringId }).then(
        (res) => {
          this.structuralPartsList = res.data;
        }
      );
    },
    contractIdFun() {
      let item = this.contractIdList.find(
        (res) => res.contractId == this.formData.contractId
      );
      console.log(item);
      this.formData.contractId = item.contractId;
      queryCooperationEngineering({contractId:item.contractId}).then(res=>{
        this.engineeringNameList = res.data
      })
    },
    /**协外单位查询 */
    async contractIdListFun(type) {
      if (type) {
        this.formData.contractId = "";
        this.formData.contractNo = "";
      }
      if (!this.formData.stationId) {
        this.$message({
          message: "请先选择站点！",
          type: "warning",
        });
        this.formData.orderType = "";
        return;
      }
      await getContractVoList({
        stationId: this.formData.stationId,
        contractTypeId: 5,
      }).then((res) => {
        this.contractIdList = this.copy(res.data);
      });
    },
    selectableFun(row) {
      if (row.approvalStatus !== 4) {
        return true;
      }
    },
    handleSelectionChange(val) {
      this.ids = val;
    },
    cancelPlanByIdsFun() {
      if (this.ids.length == 0) {
        this.$message({
          message: "请选择要操作的数据项",
          type: "warning",
        });
        return;
      }
      this.$confirm("此操作将取消订单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let arr = this.ids.map((res) => res.planId);
        cancelPlanByIds(arr).then((res) => {
          if (res.code == 1001) {
            this.ids = [];
            this.gettableData();
            this.$message({
              type: "success",
              message: "订单取消成功!",
            });
          }
        });
      });
    },
    handleSign() {
      this.signVisible = true;
      queryConfiguration().then((res) => {
        if (res.code === 1001) {
          this.signParams = res.data;
        }
      });
    },
    handleSure() {
      updateConfiguration(this.signParams).then((res) => {
        if (res.code === 1001) {
          this.$message.success("设置成功");
          this.signVisible = false;
        }
      });
    },
    /**通过站点查询公司 */
    get_simple_organizationFun(id) {
      get_simple_organization({ id: id }).then((res) => {
        this.formData.companyId = res.data.id;
        this.formData.company = res.data.name;
      }); //查询站点所属公司
    },
    /*根据公司获取站点*/
    setstationIdlist(companyId) {
      getStationByCompanyId({ id: companyId }).then((res) => {
        this.sitelist = res.data;
        this.toViewList2_1 = this.copy(this.sitelist);
        this.sitelist.map((v) => {
          v.id = v.stationId;
          v.name = v.stationName;
        });
      });
    },
    //都是生产调整里面的表格操作-------------------------------------------开始
    addDialog2_2UPFun() {
      if (this.multipleSelection != "") {
        if (this.multipleSelection.contractId) {
          //外协生产-合同
          this.formData2.list[this.toViewListIndex].foreignType = "type_unit";
          this.formData2.list[this.toViewListIndex].foreignId =
            this.multipleSelection.supplierId;
          this.formData2.list[this.toViewListIndex].foreignName =
            this.multipleSelection.supplierName;
          this.formData2.list[this.toViewListIndex].contractId =
            this.multipleSelection.contractId;
          this.formData2.list[this.toViewListIndex].contractNo =
            this.multipleSelection.contractNumber;
          this.formData2.list[this.toViewListIndex].orderType = 3;
        } else {
          //自主生产-站点的
          this.formData2.list[this.toViewListIndex].foreignType =
            "type_station";
          this.formData2.list[this.toViewListIndex].foreignId =
            this.multipleSelection.stationId;
          this.formData2.list[this.toViewListIndex].foreignName =
            this.multipleSelection.stationName;
        }
        this.addDialog2_2 = false;
      } else {
        this.$message({
          message: "请选择数据！",
          type: "warning",
        });
      }
    },
    handleSelectionChange2(val) {
      this.multipleSelection = val;
    },
    handleSelectionChange1(val) {
      this.multipleSelection = val;
      // //站点选中项
      // let type = this.formData2.list.findIndex((res, k) => this.toViewListIndex != k && res.foreignId == val.stationId)
      // if (type == -1) {
      //   this.multipleSelection = val;
      // } else {
      //   this.$message({
      //     message: '该选项已被选择！',
      //     type: 'warning'
      //   });
      //   setTimeout(() => {
      //     this.multipleSelection = ''
      //   }, 100);
      // }
    },
    addDialog2_2False() {
      setTimeout(() => {
        this.addDialog2_2 = false;
      }, 200);
    },
    async addDialog2_2Fun(index, row) {
      this.multipleSelection = "";
      //外协合同显示开始------------------------------
      await getContractVoList({
        stationId: this.formData2_2.pointId,
        contractTypeId: 5,
      }).then((res) => {
        this.toViewList2_2 = this.copy(res.data);
      });
      this.toViewListIndex = index;
      this.addDialog2_2 = true;
      console.log(this.toViewList2_1);
      console.log(this.toViewList2_2);
      if (row.foreignId) {
        let arr = [...this.toViewList2_1, ...this.toViewList2_2];
        arr.forEach((v) => {
          v.idCopy = v.contractId ? v.contractId : v.id;
        });
        this.multipleSelection = arr.find((res) => res.idCopy == row.foreignId);
      }
    },
    formData3TableListCopyAddFun() {
      //日期的添加
      this.formData3TableTimeListCopy2.push({
        planDate: "",
        id: "",
        planId: this.planId,
        status: 1,
      });
    },
    //都是生产调整里面的表格操作-------------------------------------------结束
    graphic_listFun(d) {
      //根据所选工程查询浇筑部位（图算管理）
      graphic_list({ engineeringId: d }).then((res) => {
        this.structuralPartsList = res.data;
      });
    },
    radioAddFun() {
      //作业安排-泵送，运输，泵管；选择后的显示和赋值
      this.chooseType = false;
      if (this.ToViewFun3Name == "选择前场工长") {
        // this.formData2_2.foremanId = this.radio.id;
        // this.formData2_2.foreman = this.radio.name;
        const { oldPermissionsList } = this;
        const newData1 = this.foremanIdList.filter((item) =>
          this.checkList1.some((items) => item.id === items)
        );
        const newData2 = this.foremanIdList2.filter((item) =>
          this.checkList2.some((items) => item.id === items)
        );
        const newData3 = this.foremanIdList3.filter((item) =>
          this.checkList3.some((items) => item.id === items)
        );
        const newData4 = this.foremanIdList3.filter((item) =>
          this.checkList4.some((items) => item.id === items)
        );
        const newData = [...newData1, ...newData2, ...newData3];
        this.formData2_2.foreman = [...newData, ...newData4]
          .map((item) => item.name)
          .join(",");
        this.formData2_2.foreManList = newData.map((item) => ({
          organizationId: this.formData2_2.pointId,
          foreMan: item.name,
          foreManId: item.id,
        }));
        if (oldPermissionsList.length) {
          const allHasData = oldPermissionsList
            .filter((item) =>
              this.checkList4.some((items) => items === item.userId)
            )
            .map((item) => ({
              planId: this.planId,
              userId: item.userId,
              id: item.id,
            }));
          const deleteData = oldPermissionsList
            .filter(
              (item) =>
                !allHasData.some((items) => items.userId === item.userId)
            )
            .map((item) => ({
              planId: this.planId,
              userId: item.userId,
              id: item.id,
              status: 0,
            }));
          const addData = newData4
            .filter(
              (item) => !allHasData.some((items) => items.userId === item.id)
            )
            .map((item) => ({ planId: this.planId, userId: item.id }));
          this.formData2_2.schedulingPermissionList = [
            ...allHasData,
            ...deleteData,
            ...addData,
          ];
          return;
        } else {
          this.formData2_2.schedulingPermissionList = newData4.map((item) => ({
            planId: this.planId,
            userId: item.id,
          }));
        }
      } else if (this.ToViewFun3Name == "选择泵送队" && this.radio) {
        this.formData2_2.pumpingTeam =
          this.radio.contractNumber + ":" + this.radio.supplierName;
        this.formData2_2.pumpingTeamId = this.radio.contractId;
        this.formData2_2.dataType = this.radio.dataType;
      } else if (this.ToViewFun3Name == "选择罐车合同" && this.radio) {
        this.formData2_2.tankCar =
          this.radio.contractNumber + ":" + this.radio.supplierName;
        this.formData2_2.tankCarId = this.radio.contractId;
      } else if (this.ToViewFun3Name == "选择泵管单位" && this.radio) {
        this.formData2_2.pipeName =
          this.radio.contractNumber + ":" + this.radio.supplierName;
        this.formData2_2.pipeId = this.radio.contractId;
      }
    },
    radioFun(res) {
      //作业安排-泵送，运输，泵管；的单选
      this.radio = res;
    },
    async ToViewFun3(name) {
      if (!this.formData2_2.pointId) {
        this.$message({
          message: "请选择供应站点！",
          type: "warning",
        });
        return;
      }
      //作业安排-泵送，运输，泵管；的弹出列表
      this.chooseType = true;
      this.radio = "";
      let id = "";
      if (name == "前场工长") {
        this.ToViewFun3Name = "选择前场工长";
        return;
      } else if (name == "泵送") {
        this.ToViewFun3Name = "选择泵送队";
        await getContractVoList({
          stationId: this.formData2_2.pointId,
          contractTypeId: 3,
          facilityType: 1,
        }).then((res) => {
          this.toViewList2 = res.data;
          id = this.formData2_2.pumpingTeamId;
        });
      } else if (name == "运输") {
        this.ToViewFun3Name = "选择罐车合同";
        await getContractVoList({
          stationId: this.formData2_2.pointId,
          contractTypeId: 2,
        }).then((res) => {
          this.toViewList2 = res.data;
          id = this.formData2_2.tankCarId;
        });
      } else if (name == "泵管") {
        this.ToViewFun3Name = "选择泵管单位";
        await getContractVoList({
          stationId: this.formData2_2.pointId,
          contractTypeId: 4,
        }).then((res) => {
          this.toViewList2 = res.data;
          id = this.formData2_2.pipeId;
        });
      }
      this.toViewList2.forEach((v) => {
        if (v.contractId == id) {
          this.radio = v;
        }
      });
    },
    //点击调整
    async ToViewFun2(e, customerCheckStatus, orderType) {
      console.log(e);
      this.customerCheckStatusCode = customerCheckStatus;
      this.customerCheckStatus = false;
      if (
        customerCheckStatus == 3 ||
        customerCheckStatus == 4 ||
        customerCheckStatus == 5 ||
        customerCheckStatus == 6
      ) {
        this.customerCheckStatus = true; //客户确认状态2,4是已确认和已完成，只能查看
      }

      this.orderType = orderType; //客户还是调整订单

      this.addDialog2 = true;
      this.planId = e.planId;
      this.engineeringId = e.engineeringId;
      this.getDisClostDisAddCostFun(e.engineeringId);
      await this.setstationIdlist(e.companyId);
      /**历史备注 */
      planRemark({ planId: this.planId }).then((res) => {
        this.remarkList = res.data;
      });
      /**作业泵工 */
      await assign_list({ planId: this.planId }).then((res) => {
        if (res.data.length) {
          let newArry = [];
          for (let i = 0; i < res.data.length; i += 1) {
            newArry = newArry.concat(res.data[i].pumpMans || []);
          }
          this.foremanIdList3 = newArry.map((v) => {
            return { id: v.pumpManId, name: v.pumpManName };
          });
        }
      });
      plan_detail_and_child({ id: this.planId }).then((res) => {
        //获取订单信息
        if (res.code == 1001) {
          this.formData2 = { ...this.formData2, ...res.data };
          if (this.formData2.noteName == "") {
            this.formData2.noteName = this.formData2.productName;
          }
          this.servicePoint = this.formData2.servicePoint
            ? JSON.parse(this.formData2.servicePoint)
                .map((item) => item.name)
                .join(",")
            : "";
          this.buspointids = this.formData2.servicePoint
            ? JSON.parse(this.formData2.servicePoint).map((item) => item.id)
            : [];
          this.$forceUpdate();
          operation_detail({
            //获取作业安排信息
            planId: this.planId,
            enginnerId: this.engineeringId,
          }).then((res2) => {
            if (res2.code == 1001) {
              this.formData2_2 = { ...this.formData2_2, ...res2.data };
              if (!this.formData2_2.pointId)
                this.formData2_2.pointId = e.stationId;
              this.oldPermissionsList = res2.data.schedulingPermissions;
              /**查询前场工长的用户 */
              get_simple_user_listBycompanyId({
                roleId: "e92df33754444146b8e063b9d17ee99b",
                orgznizationId: this.formData2.companyId,
                stationId: this.formData2_2.pointId,
              }).then((res) => {
                this.foremanIdList = res.data;
              });
              /**后场工长 */
              get_simple_user_list({
                orgznizationId: this.formData2_2.pointId,
                roleId: "22355b8155c24a458b7c32800e4bd8f9",
              }).then((res) => {
                this.foremanIdList2 = res.data;
                this.checkList2 = this.foremanIdList2
                  .filter((item) =>
                    res2.data.foreMans?.some(
                      (items) => items.foreManId === item.id
                    )
                  )
                  ?.map((item) => item.id);
              });
              const foreman1 =
                res2.data.foreMans?.map((item) => item.foreMan) || [];
              const foreman2 = res2.data.schedulingPermissions?.map((item) => {
                for (let i = 0; i < this.foremanIdList3.length; i += 1) {
                  if (this.foremanIdList3[i].id === item.userId) {
                    return this.foremanIdList3[i].name;
                  }
                }
              });
              this.formData2_2.foreman = [...foreman1, ...foreman2].join(",");
              this.checkList1 = this.foremanIdList
                .filter((item) =>
                  res2.data.foreMans?.some(
                    (items) => items.foreManId === item.id
                  )
                )
                ?.map((item) => item.id);
              this.checkList3 = this.foremanIdList3
                .filter((item) =>
                  res2.data.foreMans?.some(
                    (items) => items.foreManId === item.id
                  )
                )
                ?.map((item) => item.id);
              this.checkList4 = res2.data.schedulingPermissions?.map(
                (item) => item.userId
              );
              if (res.data.list.length > 0) {
                this.formData2.list = res.data.list; //表格数据！！！！！！！！！！！！！！
                this.$refs.formData2List.doLayout();
              } else {
                let foreignId, foreignName;
                if (this.formData2.orderType > 2) {
                  //3，4，5就用订单基础信息的站点
                  foreignId = this.formData2.stationId;
                  foreignName = this.formData2.stationName;
                } else {
                  // 作业安排的站点
                  foreignId = this.formData2_2.pointId;
                  foreignName = this.formData2_2.pointName;
                }
                this.formData2.list.push({
                  foreignId: foreignId, //站点id/主合同单位id
                  foreignType: "type_station", //type_station：站点；type_unit:主合同单位
                  foreignName: foreignName, //站点名称/主合同单位名称
                  pouringNum: this.formData2.pouringNum, //浇筑用量
                  pouringTime: this.formData2.pouringTime, //浇筑时间
                  contractId: "", //合同id,选择合同时候传,
                  contractNo: "", //合同编号,选择合同时候传
                  status: "1", //1修改，0删除
                });
              }
              this.formData2_2.remark = "";
              if (this.remarkList?.length > 0) {
                this.formData2_2.remark = this.remarkList[0].planRemark;
              }
              get_assess({ engineeringId: this.engineeringId }).then((res3) => {
                if (res3.code == 1001) {
                  if (res3.data) {
                    this.assess.isPro = res3.data.isPro;
                  }
                  //风险管控信息,用于判断是否限制生产！isPro 1是 0否
                  plan_table_detail({ engineeringId: e.engineeringId }).then(
                    (res4) => {
                      if (res4.code == 1001) {
                        if (res4.data) {
                          this.totalPoureCount = res4.data.totalPoureCount;
                        }
                      }
                    }
                  );
                }
              });
            }
            if (this.formData2.performanceGradeId) {
              this.formData2.performanceGradeId = JSON.parse(
                this.formData2.performanceGradeId
              ).map((v) => {
                return v.id;
              });
            } else {
              this.formData2.performanceGradeId = [];
            }
            if (this.formData2.meterialRequirementsId) {
              this.formData2.meterialRequirementsId = JSON.parse(
                this.formData2.meterialRequirementsId
              ).map((v) => {
                return v.id;
              });
            } else {
              this.formData2.meterialRequirementsId = [];
            }
            if (this.formData2.specialRequirementsId) {
              this.formData2.specialRequirementsId = JSON.parse(
                this.formData2.specialRequirementsId
              ).map((v) => {
                return v.id;
              });
            } else {
              this.formData2.specialRequirementsId = [];
            }
            if (this.formData2.otherRequirementsId) {
              this.formData2.otherRequirementsId = JSON.parse(
                this.formData2.otherRequirementsId
              ).map((v) => {
                return v.id;
              });
            } else {
              this.formData2.otherRequirementsId = [];
            }
            if (this.formData2.admixtureRequirements) {
              this.formData2.admixtureRequirements = JSON.parse(
                this.formData2.admixtureRequirements
              ).map((v) => {
                return v.id;
              });
            } else {
              this.formData2.admixtureRequirements = [];
            }
            if (this.formData2.pouringMethod) {
              this.formData2.pouringMethod = JSON.parse(
                this.formData2.pouringMethod
              ).map((v) => {
                return v.id;
              });
            } else {
              this.formData2.pouringMethod = [];
            }
          });
        }
      });
      planDetail({ id: e.planId }).then((res) => {
        if (res.code === 1001) {
          if (res.data.pumpingStatus === 2) {
            this.assignment = true;
          } else {
            this.assignment = false;
          }
        }
      });
    },
    //保存并通知客户
    submit2(approvalStatus) {
      if (!this.formData2.list.length) {
        this.$message.warning("生产调整不能为空");
        return;
      }
      /**
       * @Description: 盘点逻辑 1.生产调整的生产量不能之和不能大于订单的浇筑用量
       * @param {*}
       * @Author: wangwangwang
       */
      const sum = this.formData2.list.reduce((p, e) => {
        console.log(p, e)
        if (e.status === 0) {
          return p
        } else {
          return p + e.pouringNum * 1
        }
      }, 0);
      console.log(this.formData2.list);
      console.log(sum);
      console.log(this.formData2.pouringNum);
      if (sum !== this.formData2.pouringNum * 1) {
        this.$message.warning(
          "生产调整的生产量不能之和不等于订单浇筑用量，请检查后修改"
        );
        return;
      }
      this.$refs.reffromData2.validate((valid) => {
        if (valid) {
          this.$refs.reffromData2_2.validate((valid) => {
            if (valid) {
              //通过和未通过
              let isAdjustment = false;
              this.formData2.approvalStatus = approvalStatus;
              //验证表格是否填写完整--开始
              if (
                this.formData2.list.some(
                  (listRow) =>
                    listRow.foreignName == "" ||
                    listRow.pouringTime == "" ||
                    listRow.pouringNum == 0
                )
              ) {
                this.$message({
                  message: "调整表格数据不完整，且生产量必须大于0。",
                  type: "warning",
                });
                return;
              }
              //验证表格是否填写完整--结束
              //性能等级-开始数据重装
              if (this.formData2.performanceGradeId.length > 0) {
                let arr = [];
                this.formData2.performanceGradeId.forEach((v) => {
                  this.performanceGradeList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.performanceGradeId = arr;
              }
              this.formData2.performanceGradeId = JSON.stringify(
                this.formData2.performanceGradeId
              );
              this.formData2.performanceGrade =
                this.formData2.performanceGradeId;
              //材料要求-开始数据重装
              if (this.formData2.meterialRequirementsId.length > 0) {
                let arr = [];
                this.formData2.meterialRequirementsId.forEach((v) => {
                  this.meterialRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.meterialRequirementsId = arr;
              }
              this.formData2.meterialRequirementsId = JSON.stringify(
                this.formData2.meterialRequirementsId
              );
              this.formData2.meterialRequirements =
                this.formData2.meterialRequirementsId;
              //特殊要求-开始数据重装
              if (this.formData2.specialRequirementsId.length > 0) {
                let arr = [];
                this.formData2.specialRequirementsId.forEach((v) => {
                  this.specialRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.specialRequirementsId = arr;
              }
              this.formData2.specialRequirementsId = JSON.stringify(
                this.formData2.specialRequirementsId
              );
              this.formData2.specialRequirements =
                this.formData2.specialRequirementsId;
              //其他要求-开始数据重装
              if (this.formData2.otherRequirementsId.length > 0) {
                let arr = [];
                this.formData2.otherRequirementsId.forEach((v) => {
                  this.otherRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.otherRequirementsId = arr;
              }
              this.formData2.otherRequirementsId = JSON.stringify(
                this.formData2.otherRequirementsId
              );
              this.formData2.otherRequirements =
                this.formData2.otherRequirementsId;
              //外加剂要求-开始数据重装
              if (this.formData2.admixtureRequirements.length > 0) {
                let arr = [];
                this.formData2.admixtureRequirements.forEach((v) => {
                  this.admixtureRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.admixtureRequirements = arr;
              }
              this.formData2.admixtureRequirements = JSON.stringify(
                this.formData2.admixtureRequirements
              );
              //浇筑方式-开始数据重装
              if (this.formData2.pouringMethod.length > 0) {
                let arr = [];
                this.formData2.pouringMethod.forEach((v) => {
                  this.pouringMethodList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                        type: v2.type,
                      });
                    }
                  });
                });
                this.formData2.pouringMethod = arr;
              }
              if (this.formData2.customerCheckStatus === 2) {
                isAdjustment = 1;
              }
              if (this.formData2.customerCheckStatus * 1 === 0) {
                isAdjustment = 0;
              }
              this.formData2.pouringMethod = JSON.stringify(
                this.formData2.pouringMethod
              );
              this.formData2.customerCheckStatus = 1;
              let remark = "";
              if (
                this.remarkList.length == 0 &&
                this.formData2_2.remark != ""
              ) {
                remark = this.formData2_2.remark;
              } else if (this.remarkList.length > 0) {
                if (this.formData2_2.remark != this.remarkList[0].planRemark) {
                  remark = this.formData2_2.remark;
                }
              }
              let obj = {
                arrangement: this.formData2_2,
                engineeringPlan: this.formData2,
                remark: remark, //客户订单备注修改
                isAdjustment: isAdjustment ? isAdjustment : "",
              };

              if (this.customerCheckStatusCode === 0) {
                obj.isAdjustment = 0;
              }
              /**
               * @Description: 判断流程是否被管控
               * @Param:
               * @Author: wangwangwang
               */
              if (
                this.servicePoint.length == 0 ||
                (this.servicePoint.length > 0 &&
                  this.servicePoint
                    .split(",")
                    .findIndex((res) => res == "客户计划确认") == -1)
              ) {
                obj.engineeringPlan.customerCheckStatus = 2;
                obj.engineeringPlan.erpStatus = 1;
                obj.engineeringPlan.customerCheckTime = moment().format(
                  "YYYY-MM-DD HH:mm:ss"
                );
              }
              const BoolValue = this.formData2?.list?.some(
                (item) => item.orderType === 3
              );
              //计划审核，同时支持修改订单信息和作业安排,同时修改审核状态
              if (BoolValue) {
                this.$router.push({
                  name: "sign_smartscheduld",
                  query: { obj: JSON.stringify(obj), type: 1 },
                });
                return;
              } else {
                job_arrangement(obj).then((res) => {
                  if (res.code == 1001) {
                    this.addDialog2 = false;
                    this.tableData1 = [];
                    this.$message.success("操作成功");
                    this.query_product_pageFun();
                  }
                });
              }
            } else {
              return false;
            }
          });
        } else {
          return false;
        }
      });
    },
    //添加计划
    submit() {
      this.$refs.reffromData.validate((valid) => {
        if (valid) {
          //性能等级-开始数据重装
          if (this.formData.performanceGradeId.length > 0) {
            let arr = [];
            this.formData.performanceGradeId.forEach((v) => {
              this.performanceGradeList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.performanceGradeId = arr;
            this.formData.performanceGradeId = JSON.stringify(
              this.formData.performanceGradeId
            );
            this.formData.performanceGrade = this.formData.performanceGradeId;
          } else {
            this.formData.performanceGradeId = "";
          }
          //材料要求-开始数据重装
          if (this.formData.meterialRequirementsId.length > 0) {
            let arr = [];
            this.formData.meterialRequirementsId.forEach((v) => {
              this.meterialRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.meterialRequirementsId = arr;
            this.formData.meterialRequirementsId = JSON.stringify(
              this.formData.meterialRequirementsId
            );
            this.formData.meterialRequirements =
              this.formData.meterialRequirementsId;
          } else {
            this.formData.meterialRequirementsId = "";
          }
          //特殊要求-开始数据重装
          if (this.formData.specialRequirementsId.length > 0) {
            let arr = [];
            this.formData.specialRequirementsId.forEach((v) => {
              this.specialRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.specialRequirementsId = JSON.stringify(arr);
            this.formData.specialRequirements =
              this.formData.specialRequirementsId;
          } else {
            this.formData.specialRequirementsId = "";
          }
          //其他要求-开始数据重装
          if (this.formData.otherRequirementsId.length > 0) {
            let arr = [];
            this.formData.otherRequirementsId.forEach((v) => {
              this.otherRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.otherRequirementsId = JSON.stringify(arr);
            this.formData.otherRequirements = this.formData.otherRequirementsId;
          } else {
            this.formData.otherRequirementsId = "";
          }
          //外加剂要求-开始数据重装
          if (this.formData.admixtureRequirements.length > 0) {
            let arr = [];
            this.formData.admixtureRequirements.forEach((v) => {
              this.admixtureRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.admixtureRequirements = JSON.stringify(arr);
          } else {
            this.formData.admixtureRequirements = "";
          }
          //浇筑方式-开始数据重装
          if (this.formData.pouringMethod.length > 0) {
            let arr = [];
            this.formData.pouringMethod.forEach((v) => {
              this.pouringMethodList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                    type: v2.type,
                  });
                }
              });
            });
            this.formData.pouringMethod = JSON.stringify(arr);
          } else {
            this.formData.pouringMethod = "";
          }
          this.formData.approvalStatus = 2;
          this.formData.customerCheckStatus = 0;
          this.formData.engineeringName = this.formData.engineeringNameRemark
          this.structuralPartsFun();
          save_or_update(this.formData).then((res) => {
            if (res.code == 1001) {
              this.addDialog = false;
              if (this.addDialogText == "添加订单") {
                this.$message({
                  message: "添加成功",
                  type: "success",
                });
              } else {
                this.$message({
                  message: "修改成功",
                  type: "success",
                });
              }
              this.gettableData();
            }
          });
        } else {
          return false;
        }
      });
    },
    lookFun(e) {
      this.lookType = true;
      // 组合子订单数据
      e.list.map(item => {
        item.submitOrderUserName = e.submitOrderUserName
      })
      this.subOrderList = e.list
      /**历史备注 */
      planRemark({ planId: e.planId }).then((res) => {
        this.remarkList = res.data;
      });
      plan_detail({ id: e.planId }).then((res) => {
        //获取订单信息
        this.formData4 = res.data;
        if (this.formData4.performanceGrade) {
          this.formData4.performanceGrade = JSON.parse(
            this.formData4.performanceGrade
          ).map((v) => {
            return v.name;
          });
          this.formData4.performanceGrade =
            this.formData4.performanceGrade.join(",");
        } else {
          this.formData4.performanceGrade = "";
        }
        if (this.formData4.meterialRequirements) {
          this.formData4.meterialRequirements = JSON.parse(
            this.formData4.meterialRequirements
          ).map((v) => {
            return v.name;
          });
          this.formData4.meterialRequirements =
            this.formData4.meterialRequirements.join(",");
        } else {
          this.formData4.meterialRequirements = "";
        }
        if (this.formData4.specialRequirements) {
          this.formData4.specialRequirements = JSON.parse(
            this.formData4.specialRequirements
          ).map((v) => {
            return v.name;
          });
          this.formData4.specialRequirements =
            this.formData4.specialRequirements.join(",");
        } else {
          this.formData4.specialRequirements = "";
        }
        if (this.formData4.otherRequirements) {
          this.formData4.otherRequirements = JSON.parse(
            this.formData4.otherRequirements
          ).map((v) => {
            return v.name;
          });
          this.formData4.otherRequirements =
            this.formData4.otherRequirements.join(",");
        } else {
          this.formData4.otherRequirements = "";
        }
        operation_detail({
          //获取作业安排信息
          planId: e.planId,
          enginnerId: e.engineeringId,
        }).then((res2) => {
          let obj = {
            point: res2.data.pointName,
            settle: "",
            lossNumId: res2.data.lossNumId,
            remark2: res2.data.remark,
            settleName: res2.data.settleName,
            settleId: res2.data.settleId,
            lossNum: res2.data.lossNum,
            foreman: res2.data.foreman,
          };
          this.formData4 = { ...this.formData4, ...obj };
        });
      });
    },
    resetParams() {
      /*重置数据*/
      let curTime = new Date().Format('yyyy-MM-dd hh:mm:ss')
      let startTime = new Date().Format('yyyy-MM-dd')
      startTime = (new Date(startTime)).getTime() - 24 * 60 * 60 * 1000
      startTime = (new Date(startTime)).Format('yyyy-MM-dd') + ' 00:00:00'
      let params = {
        ...this.tableParam,
        startTimDateEndTimDate: [],
        productName: "",
        customerName: "",
        startDate: "",
        endDate: "",
        structuralParts: "",
        time: [startTime, curTime],
        stationId: "",
      };
      if (this.UserInfo.pointIds.length === 1) {
        params.stationId = this.UserInfo.pointIds[0]
      }
      this.$data.tableParam = params;
    },
    init() {
      this.resetParams()
      this.approvalStatus0 = "";
      this.tableParam.approvalStatus = "";
      if (this.currenindex == 1) {
        this.tableParam.approvalStatus = 2;
        this.customerCheckStatus0 = "";
        this.tableParam.customerCheckStatus = "";
        this.query_product_pageFun();
        return;
      }
      this.serachSubmit()
    },
    choose(num) {
      this.resetParams()
      this.currenindex = num;
      if (num == 0) {
        this.approvalStatus0 = "";
        this.tableParam.approvalStatus = "";
        this.gettableData();
      } else if (num == 1) {
        this.tableParam.approvalStatus = 2;
        this.query_product_pageFun();
      } else {
        this.tableParam.approvalStatus = 2;
        this.gettableData();
      }
    },
    advancedSearch() {
      if (this.currenindex === 0) {
        this.approvalStatus0 = "";
        this.tableParam.approvalStatus = "";
        this.gettableData();
      } else {
        this.tableParam.approvalStatus = 2;
        this.query_product_pageFun();
      }
    },
    chongZhi() {
      this.engineeringNameList = [];
      this.$data.formData = this.$options.data().formData;
      this.$nextTick(() => {
        this.$refs.reffromData.clearValidate();
        this.$data.formData.approvalStatus = 2;
        this.$data.formData.customerCheckStatus = 2;
      });
    },
    chongZhi2() {
      this.$data.formData2 = this.$options.data().formData2;
      setTimeout(() => {
        this.$refs.reffromData2.clearValidate();
      }, 100);
    },
    /**浇筑部位校验是输入还是选择 */
    structuralPartsFun() {
      let item = this.structuralPartsList.find(
        (v) => v.id == this.formData.structuralParts
      );
      if (item) {
        this.formData.structuralPartsId = this.formData.structuralParts;
        this.formData.structuralParts = item.structuralParts;
      } else {
        this.formData.structuralPartsId = "";
      }
    },
    /**查询该工程的强度等级+各项要求+浇筑部位 */
    getDisClostDisAddCostFun(id) {
      getDisClostDetail({ id }).then((res) => {
        if (res.code === 1001 && res.data) {
          this.strengthGradeList = JSON.parse(res.data.strengthGrade);
          this.performanceGradeList = JSON.parse(res.data.performanceRate);
          //材料要求pouringMethodList
          this.meterialRequirementsList = JSON.parse(
            res.data.materialRequirements
          );
          //特殊要求
          this.specialRequirementsList = JSON.parse(
            res.data.specialRequirements
          );
          //外加剂要求
          this.admixtureRequirementsList = JSON.parse(
            res.data.admixtureRequirements
          );
          //其他要求
          this.otherRequirementsList = JSON.parse(res.data.otherRequirements);
          //浇筑方式
          this.pouringMethodList = JSON.parse(res.data.pumpType);
        }
      });
    },
    look0Fun(low) {
      this.$data.formData = this.$options.data().formData;
      this.look0Type = true;
      this.addDialogText = "订单详情";
      plan_detail({ id: low.planId }).then((res) => {
        //获取订单信息
        this.formData = res.data;
        this.engineeringManagementQueryListFinishFun();
        if (this.formData.performanceGrade) {
          this.formData.performanceGrade = JSON.parse(
            this.formData.performanceGrade
          ).map((v) => {
            return v.name;
          });
          this.formData.performanceGrade =
            this.formData.performanceGrade.join(",");
        } else {
          this.formData.performanceGrade = "";
        }
        if (this.formData.meterialRequirements) {
          this.formData.meterialRequirements = JSON.parse(
            this.formData.meterialRequirements
          ).map((v) => {
            return v.name;
          });
          this.formData.meterialRequirements =
            this.formData.meterialRequirements.join(",");
        } else {
          this.formData.meterialRequirements = "";
        }
        if (this.formData.specialRequirements) {
          this.formData.specialRequirements = JSON.parse(
            this.formData.specialRequirements
          ).map((v) => {
            return v.name;
          });
          this.formData.specialRequirements =
            this.formData.specialRequirements.join(",");
        } else {
          this.formData.specialRequirements = "";
        }
        if (this.formData.otherRequirements) {
          this.formData.otherRequirements = JSON.parse(
            this.formData.otherRequirements
          ).map((v) => {
            return v.name;
          });
          this.formData.otherRequirements =
            this.formData.otherRequirements.join(",");
        } else {
          this.formData.otherRequirements = "";
        }
        if (this.formData.pouringMethod) {
          this.formData.pouringMethod = JSON.parse(
            this.formData.pouringMethod
          ).map((v) => {
            return v.name;
          });
          this.formData.pouringMethod = this.formData.pouringMethod.join(",");
        } else {
          this.formData.pouringMethod = "";
        }
      });
    },
    serachSubmit() {
      this.tableParam.page = 1;
      if (this.tableParam.time?.length === 2) {
        this.tableParam.createStart = this.tableParam.time[0];
        this.tableParam.createEnd = this.tableParam.time[1];
      }
      this.gettableData();
    },
    query_product_pageFun() {
      //生产调整
      if (this.tableParam.time?.length === 2) {
        this.tableParam.createStart = this.tableParam.time[0];
        this.tableParam.createEnd = this.tableParam.time[1];
      }
      query_product_page(this.tableParam).then((res) => {
        this.total = res.data.totalRows;
        res.data.data.map(item => {
          item.sizeY = 1
        })
        this.tableData1 = res.data.data
        // if (res.data.data.length > 0) {
        //   let d = res.data.data;
        //   let orderNo = "",
        //     approvalStatus = "",
        //     customerCheckStatus = "",
        //     sizeY = "";
        //   let arr = [];
        //   d.forEach((v) => {
        //     if (v.list.length > 0) {
        //       sizeY = v.list.length;
        //       orderNo = v.orderNo;
        //       approvalStatus = v.approvalStatus;
        //       customerCheckStatus = v.customerCheckStatus;
        //       let obj = {
        //         sizeY: sizeY,
        //         type: false,
        //       };
        //       v.list.forEach((v2, k2) => {
        //         let obj2 = {
        //           ...v,
        //           // ...v2,
        //           orderNo: orderNo,
        //           approvalStatus: approvalStatus,
        //           customerCheckStatus: customerCheckStatus,
        //         };
        //         if (k2 != 0) {
        //           obj.sizeY = 0;
        //         }
        //         arr.push({ ...obj, ...obj2 });
        //       });
        //       //orderNo这里其实是计算的合计
        //     } else {
        //       v.sizeY = 1;
        //       arr.push(v);
        //     }
        //   });
        //   this.tableData1 = arr;
        //   this.$nextTick(() => {
        //     this.$refs.table1.doLayout();
        //   });
        // } else {
        //   this.tableData1 = [];
        // }
      });
    },
    //合并行列
    objectSpanMethod({ row, columnIndex }) {
      //第一列合并列数，被合并的要返回[0,0]
      if (columnIndex == 0) {
        return [row.sizeY, 1];
      } else if (columnIndex == 0) {
        return [0, 0];
      }
      if (columnIndex == 9) {
        return [row.sizeY, 1];
      } else if (columnIndex == 9) {
        return [0, 0];
      }
      if (columnIndex == 10) {
        return [row.sizeY, 1];
      } else if (columnIndex == 10) {
        return [0, 0];
      }
      //第二列合并行数，被合并的要返回[0,0]
      // if (row.type && columnIndex == 1) {
      //   return [1, 5]
      // } else if (row.type && columnIndex > 1) {
      //   return [0, 0]
      // }
    },
    choiseBussinessPoint() {
      this.bussinessVisible = true;
    },
    handlePoint() {
      const newData = this.buspointArr.filter((item) =>
        this.buspointids.some((items) => item.id === items)
      );
      this.servicePoint = newData.map((item) => item.name).join(",");
      this.formData2.servicePoint = JSON.stringify(
        newData.map((item) => ({ id: item.id, name: item.name, type: 1 }))
      );
      this.bussinessVisible = false;
    },
    addListFun() {
      this.formData2.list.push({
        foreignId: "", //站点id/主合同单位id
        foreignType: "", //type_station：站点；type_unit:主合同单位
        foreignName: "", //站点名称/主合同单位名称
        pouringNum: 0, //浇筑用量
        pouringTime: "", //浇筑时间
        contractId: "", //合同id,选择合同时候传,
        contractNo: "", //合同编号,选择合同时候传
        status: "1", //1修改，0删除
      });
      this.$nextTick(() => {
        setTimeout(() => {
          this.$refs.FZYinfo.scrollIntoView({
            block: "end",
            behavior: "smooth",
          });
        }, 100);
      });
    },
    deleteItem(index, row) {
      if (row.id) {
        row.status = 0;
      } else {
        this.formData2.list.splice(index, 1);
      }
    },
    tableRowClassName({ row }) {
      if (row.status == 0) {
        return "display-row-FzyHeight";
      }
    },
    tableRowClassName2({ row }) {
      if (row.customerCheckStatus === 0) {
        return "success-row";
      } 
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.query_product_pageFun();
    },
    sizeChange2(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    },
  },
  filters: {
    pouringMethodFilter(e) {
      if (e) {
        e = JSON.parse(e);
        let table = e.map((res) => res.name);
        let text = table.join("、");
        return text;
      }
    },
  },
};
